package xp2p.adv.jxta;

import java.net.URI;

import net.jxta.document.Advertisement;
import net.jxta.document.AdvertisementFactory;
import net.jxta.document.Element;
import net.jxta.document.MimeMediaType;
import net.jxta.id.ID;
import net.jxta.peergroup.PeerGroupID;

public class JobAdv extends AdvBase
{
	public static class Instantiator implements
			AdvertisementFactory.Instantiator
	{

		public String getAdvertisementType()
		{
			return JobAdv.DocType;
		}

		public Advertisement newInstance()
		{
			return new JobAdv();
		}

		public Advertisement newInstance(Element root)
		{
			return new JobAdv(root);
		}
	}
	
	private final static String ClassTag = "class";
	private final static String AppTag = "app";	
	private final static String RankTag = "rank";	
	private final static String RunStateTag = "state";
	private final static String StateTag = "status";
	
	public static final String DocType = "jxta:xp2pjobadv" ;	
	

	public static void RegisterSelf()
	{
		AdvertisementFactory.registerAdvertisementInstance(DocType,
				new Instantiator());
	}

	public JobAdv()
	{
		super();
	}

	public JobAdv(Element root)
	{
		super(root);
	}
	

	@Override
	public JobAdv clone() throws CloneNotSupportedException
	{
		return new JobAdv(this.getStructuredDocument(MimeMediaType.XMLUTF8)
				.getRoot());
	}

	@Override
	protected void DefineProps()
	{
		super.DefineProps();
		Properties.put(ClassTag, null);
		Properties.put(RankTag, null);
		Properties.put(StateTag, null);
		Properties.put(RunStateTag, null);
		Properties.put(AppTag, null);
	}
	
	@Override
	public String getDocType()
	{
		return DocType; 
	}

	public PeerGroupID getPeerGroupID()
	{
		return PeerGroupID.create(URI.create((String) Properties.get(AppTag)));
	}	

	public void setPeerGroupID(PeerGroupID id)
	{
		Properties.put(AppTag, id.toURI().toString());
	}
}
